package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Feedback;
import com.cskaoyan.service.WxFeedbackService;
import com.cskaoyan.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yudefu
 * @date 2021年06月08日  11:40
 * @description: 反馈模块
 */

@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {

    @Autowired
    WxFeedbackService wxFeedbackService;

    @RequestMapping("submit")
    public BaseRespVo submitFeedback(@RequestBody Feedback feedback) {

        //校验手机号码
        if (!(StringUtils.wxFeedbackMobileVerification(feedback.getMobile()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

        if (StringUtils.isEmpty(feedback.getContent())) {
            return BaseRespVo.fail(402, "参数值不对");
        }

        //校验反馈类型
        if (!(StringUtils.wxFeedbackFeedTypeVerification(feedback.getFeedType()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }


        int res = wxFeedbackService.submitFeedback(feedback);

        if (res > 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }
}
